home *** CD-ROM | disk | FTP | other *** search
- Path: newshost.lanl.gov!tanmoy
- From: tanmoy@qcd.lanl.gov (Tanmoy Bhattacharya)
- Newsgroups: comp.lang.c
- Subject: Re: Floating point calculation order
- Date: 25 Jan 1996 01:10:45 GMT
- Organization: Los Alamos National Laboratory
- Message-ID: <TANMOY.96Jan24181045@qcd.lanl.gov>
- References: <m0tedv8-0002eqC@sice.nsk.su> <3104c6d9.134061184@nntp.ix.netcom.com>
- <TANMOY.96Jan23144637@qcd.lanl.gov> <DLpF0C.IH4@microunity.com>
- NNTP-Posting-Host: qcd.lanl.gov
- Mime-Version: 1.0
- Content-Type: text
- In-reply-to: toms@MicroUnity.com's message of Wed, 24 Jan 1996 21:14:36 GMT
-
- --text follows this line--
- In article <DLpF0C.IH4@microunity.com> toms@MicroUnity.com (Tom
- Sanders) writes:
- <snip>
- |> I am almost certain you write `a + b * c' contrary to your claim. Do
- |> you mean `a + (b * c)' or `(a + b) * c' when, if, you do it? If you do
- |> not, you are in a very small minority.
- <snip>
- Sorry Tanmoy you'd be wrong, I do write `a + (b * c)' not `a + b * c' .
-
- I see. I had not expected such an extreme position: but de gustabis
- non est disputandum. I am used to writing long expressions, and after
- a point parentheses obscure rather than reveal.
-
- Do I need to , no of course not. I prefer to for clarity. If I specify
- exactly what I want when I write it, there is little doubt in the future
- if I or someone else is debugging a problem. If I leave the parentheses
- out, I or someone else may wonder whether it was intended to be
- `(a + b) * c' and waste time in a useless direction.
-
- I must admit that I sometimes use space and alignment for these
- purposes, but very rarely use parentheses for this purpose. I sometime
- do use parentheses when evaluation order does not matter and I want to
- stress the logical unity of a piece of the expression: even that is
- rare though.
-
- As to the original equation `p * q / r' , I would argue that parentheses
- are certainly necessary. There is a slight numeric difference between
- `(p * q) / r' and `p * (q / r)' . By specifying I am sure the order I
- prefer will be used no matter what compiler I am using.
-
- Even in non-ANSI C, there was no guarantee that the compiler will
- respect your parentheses. However, if you meant not `any' compiler:
- but any of a number of compilers, at least one of which is
- non-conformant, that you are likely to work on, I agree with you.
-
- When I write C, I assume ANSI conformance for parts which are not
- time-critical. Parts which are time-critical, I have to code afresh
- for every machine anyway: this, at least so I hope, is not the
- experience of everyone.
-
- In ANSI C, a compiler is just plain wrong if it treats p * q / r as p
- * (q/r), if there is a difference between them (yes, I mean if
- numerically, there is a difference between them). The only thing ANSI
- C permits is that intermediate results may be help at higher precision
- than stored results: no reordering is allowed if it is visible by the
- program. The rules in FORTRAN (which I use more often for numerical
- work) are different.
-
- In any case, such stylistic issues can become religious. Some of my
- styles, I am sure, are religiously hated by other people. I see what
- you are saying, I think; but I do not agree with that style.
-
- Cheers
- Tanmoy
- --
- tanmoy@qcd.lanl.gov(128.165.23.46) DECNET: BETA::"tanmoy@lanl.gov"(1.218=1242)
- Tanmoy Bhattacharya O:T-8(MS B285)LANL,NM87545 H:#9,3000,Trinity Drive,NM87544
- Others see <gopher://yaleinfo.yale.edu:7700/00/Internet-People/internet-mail>,
- <http://alpha.acast.nova.edu/cgi-bin/inmgq.pl>or<ftp://csd4.csd.uwm.edu/pub/
- internetwork-mail-guide>. -- <http://nqcd.lanl.gov/people/tanmoy/tanmoy.html>
- fax: 1 (505) 665 3003 voice: 1 (505) 665 4733 [ Home: 1 (505) 662 5596 ]
-